@extends('backend::layout')
@section('title',trans($page_title))
@section('content')
    @component('backend::component.table.table-content')
        @slot('page_title') {{$page_title}} @endslot
        @slot('tools_btn')
            <a href="{{route('b_Role_showAddRoleForm')}}" class="btn btn-primary btn-sm">
                <i class="fa fa-plus"></i>&nbsp;添加角色
            </a>
        @endslot
        @slot('body_content')
            @if($list->isNotEmpty())
                <table class="table table-bordered table-striped table-condensed">
                <thead>
                <tr>
                    <th>
                        <label class="checkbox-inline">
                            @component('backend::component.checkbox')
                                @slot('name') ids-all @endslot
                            @endcomponent
                        </label>
                    </th>
                    <th>角色名称</th><th>权限</th><th>状态</th><th>操作</th>
                </tr>
                </thead>
                <tbody>
                @foreach($list as $value)
                    <tr>
                        <td>
                            <label class="checkbox-inline">
                                @component('backend::component.checkbox')
                                    @slot('name') id[] @endslot
                                    @slot('class') id @endslot
                                    @slot('value') {{$value->id}} @endslot
                                @endcomponent
                            </label>
                        </td>
                        <td>{{$value->title}}</td>
                        <td>
                            @if($value->my_auth)
                                @foreach(str2arr($value->my_auth) as $key=>$id)
                                    <code class="code">{{$action_title[$id]}}</code>
                                    @if($key>5)
                                        <a href="javascript:;" class="look-more"
                                           data-my_auth="{{$value->my_auth}}"
                                           data-action = "{{json_encode($action_title)}}"
                                        >....</a>
                                        @break
                                    @endif
                                @endforeach
                            @else
                                暂未授权
                            @endif
                        </td>
                        <td>
                            @component("backend::component.switch")
                                @slot('params'){"url":"{{route('b_Role_switchRole',['role_id'=>$value->id])}}","method":"get"} @endslot
                                @slot('checked') @if($value->status == 1) checked @endif @endslot
                            @endcomponent
                        </td>
                        <td>
                            <a href="{{route('b_Role_editRole',['role_id'=>$value->id])}}"
                               data-params='{"area":"60%,60%","title":"编辑{{$value->title}}"}'
                               class="btn btn-info btn-sm modal-box">编辑
                            </a>
                            <a href="{{route('b_Role_authRole',['role_id'=>$value->id])}}"
                               data-params='{"area":"50%,80%","title":"给{{$value->title}}授权"}'
                               class="btn btn-success btn-sm modal-box">授权
                            </a>
                            @component('backend::component.form.button')
                                @slot('title') 删除 @endslot
                                @slot('color') danger @endslot
                                @slot('size') sm @endslot
                                @slot('params') {"url":"{{route('b_Role_deleteRole',['role_id'=>$value->id])}}","confirm":"true"} @endslot
                                @slot('class') btn-ajax @endslot
                            @endcomponent
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>
            @else
                @include('backend::public.empty_page',['info'=>'暂时没有角色'])
            @endif
        @endslot
    @endcomponent
@endsection
@push('scripts')
    <script>
        layui.use(['layer'], function(){
            var layer = layui.layer,
                $ = layui.$;
            $('.look-more').each(function () {
                $(this).off('click').on('click',function () {
                    var myAuth = $(this).data('my_auth').split(',');
                    var actionTitle = $(this).data('action');
                    var content = '';
                    for (var i=0; i<myAuth.length;i++){
                       content += '<button class="btn btn-info btn-xm" style="margin:5px;">'+actionTitle[myAuth[i]]+'</button>'
                    }
                    layer.open({
                        type:1,
                        title:'所有权限',
                        area:['60%','60%'],
                        content:content
                    })
                })
            })
        });
    </script>
@endpush